/**
 * 
 */
package com.lunevich.json.tasks;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.lunevich.json.helpers.HttpManager;

import android.content.Context;

/**
 * @author Andrei_Lunevich
 *
 */
public abstract class JSONArrayAsyncTask<T> extends CommonAsyncTask<T> {
	
	private Context context;
	
	public JSONArrayAsyncTask(Context context) {
		this.context = context;
	}

	@Override
	public List<T> onLoad(String url) throws Exception {
		ArrayList<T> twitterList = new ArrayList<T>();
		JSONArray jsonArray = HttpManager.getHttpManager(context).getJSONArrayFromUrl(url, context);
		for (int i = 0; i < jsonArray.length(); i++) {
			JSONObject c = jsonArray.getJSONObject(i);
			// adding wrapper to list
			twitterList.add(createWrapper(c));
		}
		return twitterList;
	}
	
	public abstract T createWrapper(JSONObject object);
}